﻿$(document).ready(function () {
    ConfigMenu();

    $('.pnlMatto').dialog({ autoOpen: false, width: 'auto' });

    $(".dataTable tbody tr").hover(
               function () {
                   $(this).addClass("ui-state-highlight");
               },
               function () {
                   $(this).removeClass("ui-state-highlight");
               }
     );

   /* $.extend($.fn.dataTable.defaults, {
        "bJQueryUI": true,
        "sScrollY": "200px",
        "bPaginate": false,
        "bFilter": false,
        "bSort": false,
        "bInfo": false,
        "bAutoWidth": false
    });*/

    //"sScrollX": "100%",
    //"sScrollXInner": "120%"

    /*if ($(".dataTable").length) {
        $(".dataTable").dataTable(); //.fnAdjustColumnSizing();
    };*/

    ConfigPager();


});

function ConfigMenu() {
    /** arreglamos el menu*/
    $("#menu ul:first").addClass("menu");

    $("#menu ul li a:first").addClass("parent");

    $("#menu ul li ul li a:first").addClass("parent");

    $("#menu ul li:last").addClass("last");

    $("#menu a").each(function (index) {
        var a = $(this).html();
        $(this).html("<span>" + a + "</span>");
    });
}

function ConfigPager() {
    $(".dataTable input:submit").button();

    $(".pager").addClass("fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix");

    $(".firts").button({
        text: false,
        icons: { primary: "ui-icon-seek-start" }
    });

    $(".previo").button({
        text: false,
        icons: { primary: "ui-icon-seek-prev" }
    });

    $(".next").button({
        text: false,
        icons: { secondary: "ui-icon-seek-next" }
    });

    $(".end").button({
        text: false,
        icons: { secondary: "ui-icon-seek-end" }
    });

    $(".select").addClass("ui-state-highlight");

    ConfigControles();
}

function ConfigControles() {
    $("button").button();

    $(".lnkSearch").button({
        icons: { secondary: "ui-icon-search" }
    });

    $(".lnkNew").button({
        icons: { secondary: "ui-icon-plusthick" }
    });

    $(".lnkAdd").button({
        icons: { secondary: "ui-icon-circle-plus" }
    });

    $(".lnkSave").button({
        icons: { secondary: "ui-icon-disk" }
    });

    $("input:text").addClass("ui-widget-content");
}

jQuery(function ($) {
    $.extend({
        webMethod: function (method, data, onSuccess, onFail) {
            var loc = window.location.href.split('?')[0];
            if (loc.substr(loc.length - 1, 1) == "/")
                loc = loc + "Default.aspx";

            // Serialize the data object with no whitespace 
            // (.NET requirement)
            var pairs = [];
            for (var i in data) {
                pairs.push(i + ':' + data[i]);
            }
            data = '{' + pairs.join(',') + '}';

            // Perform the post operation 
            $.ajax({
                type: "POST"
                , url: loc + "/" + method
                , 'data': data
                , contentType: "application/json; charset=utf-8"
                , dataType: "json"
                , success: onSuccess
                , error: function (jqXHR, textStatus, errorThrown) {
                    // The .NET error and stacktrace is hidden 
                    // inside the XMLHttpRequest response
                    if ($.isFunction(onFail))
                        onFail($.parseJSON(jqXHR.response));
                }
            });
        }
    });
});